package cn.deluxelx.im.controller;

import cn.deluxelx.im.pojo.Message;
import cn.deluxelx.im.service.MessageService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/message")
@CrossOrigin
public class MessageController {

    @Resource
    private MessageService messageService;

    /**
     * 拉取消息列表
     *
     * @param fromId 发送端用户 ID
     * @param toId   接收端用户 ID
     * @param page   页面
     * @param rows   数据量
     * @return 消息列表
     */
    @GetMapping
    public List<Message> queryMessageList(@RequestParam("fromId") Long fromId,
                                          @RequestParam("toId") Long toId,
                                          @RequestParam(value = "page", defaultValue = "1") Integer page,
                                          @RequestParam(value = "rows", defaultValue = "10") Integer rows) {
        return messageService.queryMessageList(fromId, toId, page, rows);
    }

}
